<template>
  <view class="container">
		<nav-ber :title="check? '个人信息审核' : '个人信息'" :bgColor="'#f7f8ff'"></nav-ber>
		<view class="province">
			<uFrom  :style="{'pointer-events': !check? 'none': 'auto'}" ref="getFrom" :itemList="itemList" :itemKeys.sync="itemKeys"  @setdata="setdataFun"></uFrom>
			<view class="button_str" @click="confirm" v-if="check">
				提交
			</view>
		</view>
		<view class="proto_box"  v-if="protoIshow">
			<view class="proto_pad">
				<view class="" style="text-align: center;font-weight: bold;color: #111;">
					用户协议和隐私条款
				</view>
				<view class="font_size" style="margin-top: 40rpx;">
					欢迎您使用沙棠花小程序
				</view>
				<view class="font_size">
					请您仔细阅读<span style="color: #2979ff" @click="userAgreement">《用户协议》</span>和<span style="color: #2979ff" @click="privacyPolicy">《隐私政策》</span>,如您同意全部内容,请点击“同意”开始使用我们的服务。				
				</view>
				<view class="but_b" style="font-weight: 700;" @click="protoIshow = false">
					同意并继续
				</view>
				<view class="but_t" @click="gotoback">
					不同意
				</view>
			</view>
		</view>
  </view>
</template>
<script>
	import { medicalRepresentative, upMedicalRepresentative, userById, upUser } from '@/api/personalCenter.js'
	import { itemList } from './items.js'
  export default {
    data() {
			return {
				userDatas: {},
				protoIshow: true,
				check: true,
				show: true,
				keyword: '',
				ispro: '1',
				list: ['进行中', '已完成'],
				current: 0,
				itemList: itemList,
				itemKeys: {}
			}
    },
		onLoad(option) {
			this.medicalRepresentativeFun(option.id)
			this.userByIdFun()
			if (option.check) {
				this.check = false
				this.protoIshow = false
			} else {
				this.check = true
				
			}
		},
		methods: {
			userByIdFun() {
				userById(JSON.parse(uni.getStorageSync('userInfo')).userId).then((res) => {
					this.userDatas = res.data
				})
			},
			userAgreement() {
				uni.navigateTo({
					url: '/pages/protocol/userAgreement/index'
				})
			},
			privacyPolicy() {
				uni.navigateTo({
					url: '/pages/protocol/privacyPolicy/index'
				})
			},
			gotoback() {
				this.protoIshow = false
				uni.navigateBack({
					delta:1,
				})
			},
			setdataFun(val) {
				upUser({
					...this.userDatas,
					nickName: val.name,
					phonenumber: this.userDatas.userName
				}).then(()=>{})
				upMedicalRepresentative({
					...val,
					status: 1
				}).then((res) => {
					uni.showToast({
					  title: '保存成功',
					  icon: "none",
					  duration: 2000,
						success: () => {
							setTimeout(() => {
								uni.navigateBack({
									delta: 1,
								})
							}, 500)
						}
					})
					
				})
			},
			medicalRepresentativeFun(id) {
				medicalRepresentative(id).then((res) => {
					res.data.sexName = res.data.sex == 1? '女' : '男'
					res.data.fileList1 = []
					res.data.fileList11 = []
					res.data.fileList2 = []
					res.data.fileList3 = []
					res.data.fileList4 = []
					if (res.data.photoList.length) {
						res.data.photoList.forEach((val) => {
							if (val.type == 1) {
								if (val.category) {
									res.data.fileList1 = [val]
								} else {
									res.data.fileList11 = [val]
								}
							} else if (val.type == 2) {
								res.data.fileList2 = [val]
							} else if (val.type == 3) {
								res.data.fileList3 = [val]
							} else {
								res.data.fileList4 = [val]
							}
						})
					}
					this.itemKeys = res.data
				})
			},
			confirm() {
				this.$refs.getFrom.submit()
				// .then((res) => {
				// 	console.log(res)
				// })
			},
			proFun(val) {
				this.ispro = val
			},
			sectionChange(index) {
				this.current = index;
			},
		},
		mounted() {},
  }
</script>
<style lang="scss" scoped>
	.sea_pad {
		padding: 0 30rpx;
		box-sizing: border-box;
	}
	.container {
		background-color: #f7f8ff;
		// background-color: #fff;
		display: flex;
		flex-direction: column;
		height: 100vh;
		overflow: hidden;
	}
	.province {
		flex: 1;
		overflow: scroll;
		padding: 0 20rpx;
		margin-top: 20rpx;
		padding: 0 40rpx;
		box-sizing: border-box;
	}
	.button_str {
		width: 80%;
		margin: auto;
		text-align: center;
		border-radius: 100rpx;
		padding: 20rpx 10rpx;
		background-color: rgb(3, 121, 255);
		color: #fff;
		box-sizing: border-box;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
	}
	.proto_box {
		background-color: rgba(0,0,0, .7);
		width: 100%;
		height: 100vh;
		overflow: hidden;
		position: absolute;
		z-index: 99999;
		top: 0;
		left: 0;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.proto_pad {
		width: 600rpx;
		height: 500rpx;
		background-color: #fff;
		border-radius: 20rpx;
		padding: 30rpx;
		box-sizing: border-box;
	}
	.but_b, .but_t {
		width: 500rpx;
		padding: 20rpx;
		box-sizing: border-box;
		margin: auto;
		background-color: rgb(3, 121, 255);
		text-align: center;
		margin-top: 20rpx;
		border-radius: 50rpx;
		color: #fff;
	}
	.but_t {
		background-color: #fff;
		color: #111;
	}
	.font_size {
		font-size: 30rpx;
		color: #111;
		line-height: 44rpx;
	}
</style>
